#ifndef prs_Unit_H
#define prs_Unit_H

#include "prs_FrmFunc.h"
#include "prs_FrmStyleRule.h"
//#include "prs_odbDatabase.h"
//#include "prs_odbTable.h"
#include "prs_Form.h"
#include "prs_Menu.h"
#include "prs_Image.h"

namespace prs {

///////////////////////////////////////////////////////////////////////////////
struct TNodeUnit;
///////////////////////////////////////////////////////////////////////////////

struct TNodeUnits : public TNodeArrayT<TNodeUnit>
{
};

///////////////////////////////////////////////////////////////////////////////

struct TNodeUnit : public TNodeFrm
{
  DECLARE_ClientNode()
  //
  TAttrNodeType<nodeType_Unit> NodeType;
  TAttrId Id;
  TAttrString<attrName_Path> Path;
  TAttrString<attrName_FileName> FileName;
  //TAttrNodeArray<attrName_Units,TNodeUnits> Units;
  TAttrNodeArray<attrName_Menus,TNodeMenuBaseItems> Menus;
  TAttrNodeArray<attrName_Images,TNodeImages> Images;
  //
  snt::text::TConcreteContext SntConcreteContext;
  //
  TNodeUnit() : NodeType(this),Id(this),Path(this),FileName(this)/*,Units(this)*/,Images(this),Menus(this) {}
  //
  svl::TString GetFullFileName() { return svl::TString() << Path.GetValue() << FileName.GetValue();}
  //
  TNodeDefTemplate *SearchDefTemplateById(const svl::TString &Id){
    return TNodeDefTemplate::SearchDefTemplateById(this,Id);
  }
  //TNodeOdbDatabase *SearchDatabase();
  TNodeForm        *SearchFormById (const svl::TString &FormId);
  TNodeMenu		   *SearchMenuById (const svl::TString &MenuId);

  TNodeStyle *SearchStyleById(const svl::TString &StyleId) {
    return TNodeStyle::searchStyleByIdFromChild(this,StyleId);
  }
  //
  void SearchStyles(TNodeSearch &OutStyles);
  //
  static TNodeUnit *SearchUnitByFileNameFromChild(TAttrNode *FromChild,svl::TString &FileName);
  
private:
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

struct TRuleUnit : public snt::TRule
{
  TRuleUnit(
    snt::text::TContext &Context,
    svl::TVariant &VParentNode
  );
  
private:  
  bool FNextContext(snt::text::TNextContext::TFuncDoEntryParams &Params);
  bool FImport (snt::text::TString::TFuncClosureDoEntryParams &Params);
  //
  snt::text::TContext &context;
  svl::TVariant &vParentNode,skipImport;

  TRuleSetStyle RSetStyle;
  TRuleSetNodeIdNecessarily RSetNodeIdNecessarily;
  TRuleSetNodeIdOptionally  RSetNodeIdOptionally;
  TRuleFrmGeom RFrmGeom;
  TRuleSetAttrValue RSetAttrValue;
  TRuleFrmChildren RChildren;
  TRuleFrmValue RFrmValue;
  TRuleFrmStyle RStyle;
  TRuleDefTemplate RDefTemplate;
  TRuleForm RForm;
  TRuleMenu RMenu;
  //TRuleOdbTable ROdbTable;
  //TRuleOdbDatabase ROdbDatabase;
	
	snt::TRule RUnit,RImport;
  snt::TAlter AUnit;
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////
}

#endif
